else if (event.getRecipe() instanceof ShapelessRecipe) {
            ShapelessRecipe eventRecipe = (ShapelessRecipe) event.getRecipe();
            final CustomPlayer cp = CustomPlayer.getSettings(player);
            if (eventRecipe.getResult().equals(plugin.recipes.mobileCrazedSkullItem)) {
                boolean found = false;
                CraftingInventory ci = event.getInventory();
                int ammoCount = 0;
                for(int i = 1; i < ci.getMatrix().length; i++) {
                    ItemStack item = ci.getMatrix()[i];
                    if (isCrazedSkull(item)) {
                        found = true;
                    }
                    if (item != null && item.getType().equals(Material.ARROW)) {
                        ammoCount += item.getAmount();
                    }
                }
                if (event.getInventory() != null && event.getInventory().getType() == InventoryType.WORKBENCH) {
                    System.out.println("Craftable amount = " + cp.craftableAmount);
                }
                /*
                 * I'm thinking that this should instead of creating a skull with all the arrows
                 * and a bunch with none, this should divy up the arrows evenly between all the skulls in 
                 * any potential stack.
                 */
                if (cp.clearArrows) {
                    int maxIndex = 0;
                    if (ci.getType() == InventoryType.CRAFTING)
                        maxIndex = 4;
                    else if (ci.getType() == InventoryType.WORKBENCH)
                        maxIndex = 9;
                    for(int i = 0; i <= maxIndex; i++) {
                        if (ci.getItem(i) != null && ci.getItem(i).getType().equals(Material.ARROW)) {
                            ci.setItem(i, new ItemStack(Material.AIR));
                        }
                    }
                }
                if (ammoCount == 0) cp.clearArrows = false;
                if (found) {
                    if (!updateMobileTurretAmmoAmount(ci.getResult(), plugin.recipes.mobileCrazedLoreName, ammoCount)) return;
                }
                else {
                    event.getInventory().setItem(0, new ItemStack(Material.AIR));
                }
                if (!cp.invUpdate) {
                    cp.invUpdate = true;
                    plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

                        @SuppressWarnings("deprecation")
                        public void run() {
                            player.updateInventory();
                            cp.invUpdate = false;
                        }
                    }, 1);
                }
            }
        }


                    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    fb.setDirection(firingSolution);
                    // This needs tested - Tested still needed as of 1.7.9 Random arc is still present at lower velocities and using normal vector
                    // must setDirection from the Fireball entity instead of the entity itself
                    //firingSolution = getSpecialVector(); // Not necessary any more because of https://github.com/Bukkit/CraftBukkit/commit/bee7f7c93bd8ec20b61d68cb4db79a08099bf371
                    //velocity = (Float) (1.5F * 0.245F + (distMod / 200));
                    velocity = 0.2F;
                    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@EventHandler
    public void onPlayerAnimationEvent(final PlayerAnimationEvent event) {
        final Player player = event.getPlayer();
        final CustomPlayer cp = CustomPlayer.getSettings(player);
        final long cTime = System.currentTimeMillis();
        if (cTime - cp.attackTimer > 800) {
            if (cp.running == false) {
                cp.running = true;
                plugin.scheduler.runTaskLater(plugin, new Runnable() {

                    public void run() {

                        if (cp.skull_to_damage != null && (!cp.skull_to_damage.getSkullCreator().equals(player.getUniqueId()) || SkullTurret.DEBUG == 5)) {
                            cp.attackTimer = cTime;
                            //Block targetBlock = getTargetBlock(player, 5);
                            //if (targetBlock == null) return;

                            //if (targetBlock.getType() != Material.AIR) {
                            PlacedSkull pc = cp.skull_to_damage;
                            //Location targetLoc = targetBlock.getLocation();
                            //PlacedSkull targetSkull = plugin.skullMap.get(targetLoc);
                            //if (targetSkull != null) {
                            //    if (targetSkull != pc && (!pc.getSkullCreator().equals(player.getUniqueId()) || SkullTurret.DEBUG == 5)) {
                            //        pc = targetSkull;
                            //    }
                            //}
                            double skullHealth = pc.getHealth();
                            ItemStack weapon = player.getItemInHand();
                            if (weapon != null) {
                                Material weapType = weapon.getType();
                                if (plugin.weapons.containsKey(weapType)) {
                                    double damage = plugin.weapons.get(weapType);
                                    UUID createrUUID = pc.getSkullCreator();
                                    if (skullHealth > damage) {
                                        pc.setHealth(skullHealth - damage);
                                        pc.setRecoveryTimer(cTime);
                                        if (SkullTurret.SKULLS_RETALIATE)
                                                player.setMetadata("SkullTurretsTarget", new FixedMetadataValue(SkullTurret.plugin, new BowTargetInfo(createrUUID, System.currentTimeMillis())));

                                        //if (cTime - pc.getSfxTimer() > 1000) {
                                        pc.setSfxTimer(cTime);
                                        if (SkullTurret.SKULLSFX) {
                                            player.getWorld().playSound(pc.getCenterPoint(), Sound.SILVERFISH_HIT, (float) 0.5, 0.4F);
                                        }
                                        //}
                                        if (SkullTurret.DEBUG == 5)
                                                player.sendMessage(ChatColor.AQUA + pc.getIntelligence().getNormalName() + ChatColor.RED + " Skull's Health is " + ChatColor.GOLD + pc.getHealth() + ChatColor.RED + " of " + ChatColor.GOLD + pc.getIntelligence().getHealth());
                                    }
                                    else if (!pc.isDying()) {
                                        pc.setHealth(0);
                                        // TODO Death rattle
                                        pc.setDestructTimer(cTime);
                                        pc.setDying(true);
                                        pc.doDeathRattle(cTime, cTime, SkullTurret.DESTRUCT_TIMER);
                                        if (SkullTurret.SKULLSFX) {
                                            player.getWorld().playSound(pc.getCenterPoint(), Sound.SILVERFISH_KILL, (float) 0.5, 0.4F);
                                        }
                                        if (SkullTurret.SKULLS_RETALIATE)
                                                player.setMetadata("SkullTurretsTarget", new FixedMetadataValue(SkullTurret.plugin, new BowTargetInfo(createrUUID, System.currentTimeMillis())));
                                    }
                                }
                                else if (pc.getIntelligence().getRepair_item().equals(weapType)) {
                                    double repairAmt = SkullTurret.SKULL_REPAIR_AMOUNT;
                                    if (pc.getHealth() < pc.getIntelligence().getHealth()) {
                                        pc.setHealth(skullHealth + repairAmt);
                                        if (pc.getHealth() >= pc.getIntelligence().getHealth()) {
                                            pc.setDying(false);
                                            pc.setHealth(pc.getIntelligence().getHealth());
                                            removeRepairItem(weapon, player);
                                        }
                                        //if (cTime - pc.getSfxTimer() > 1000) {
                                        pc.setSfxTimer(cTime);
                                        if (SkullTurret.SKULLSFX) {
                                            player.getWorld().playSound(pc.getCenterPoint(), Sound.ORB_PICKUP, (float) 0.5, 0.5F);
                                        }
                                        //}
                                        if (SkullTurret.DEBUG == 5)
                                                player.sendMessage(ChatColor.AQUA + pc.getIntelligence().getNormalName() + ChatColor.GREEN + " Skull's Health is " + ChatColor.GOLD + pc.getHealth() + ChatColor.GREEN + " of " + ChatColor.GOLD + pc.getIntelligence().getHealth());
                                    }
                                    else {
                                        pc.setDying(false);
                                        pc.setHealth(pc.getIntelligence().getHealth());
                                        int amount = weapon.getAmount();
                                        if (amount > 1) {
                                            removeRepairItem(weapon, player);
                                        }
                                        else {
                                            removeRepairItem(weapon, player);
                                        }
                                    }
                                }
                            }
                        }
                        //}
                        cp.running = false;
                    }
                }, 1);
            }
        }
    }
    
        private Block getTargetBlock(Player player, int range) {
        try {
            BlockIterator iter = new BlockIterator(player, range);
            Block lastBlock = iter.next();
            while (iter.hasNext()) {
                lastBlock = iter.next();
                if (lastBlock.getType() == Material.AIR)
                    continue;
                break;
            }
            return lastBlock;
        } catch (Exception e) {
            return null;
        }
    }

package plugin.arcwolf.skullturrets;

import java.util.Arrays;
import java.util.Map;
import java.util.UUID;

public class UUIDHelper {

    SkullTurret plugin;

    public UUIDHelper(SkullTurret plugin) {
        this.plugin = plugin;
    }

    /*
     * This is an example of how to use UUID fetcher.
     * 
     * It must be used on a async thread because the requests to the HTTP server are blocking and could lock up the minecraft server
     * it is ran on.
     * 
     * This could also throw errors if minecraft servers are down. In this case I need to come up with some kind of contengincy plan
     * because I still need to find the uuid / name
     */
    public void example() {
        UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList("evilmidget38", "mbaxter"));

        Map<String, UUID> response = null;
        try {
            response = fetcher.call();
        } catch (Exception e) {
            plugin.getLogger().warning("Exception while running UUIDFetcher");
            e.printStackTrace();
        }
    }
}

private boolean inGameLegacyCommands(CustomPlayer cp, Player player, CommandSender sender, Command cmd, String commandLabel, String[] args) {
        if (cmd.getName().equalsIgnoreCase("skskin") && plugin.hasPermission(player, "skullturret.skin")) {
            if (cp.pc == null) {
                sender.sendMessage(ChatColor.RED + "You must click a skull first");
                return true;
            }
            if (cp.pc.getIntelligence().canSkinChange()) {
                if (args.length == 0) {
                    cp.pc.setSkin("");
                    sender.sendMessage(ChatColor.GREEN + "Skulls Skin reset");
                }
                else {
                    cp.pc.setSkin(args[0]);
                    sender.sendMessage(ChatColor.GREEN + "This skulls skin set to use " + ChatColor.GOLD + args[0]);
                }
            }
            else {
                sender.sendMessage(ChatColor.RED + "Sorry " + cp.pc.getIntelligence().getNormalName() + " Skulls can not change their skin.");
                return true;
            }
        }
        else if (cmd.getName().equalsIgnoreCase("skdebug") && plugin.hasPermission(player, "skullturret.debug")) {
            if (args.length == 0)
                SkullTurret.DEBUG = 0;
            else if (args.length == 1) {
                try {
                    int d = Integer.parseInt(args[0]);
                    SkullTurret.DEBUG = d;
                } catch (Exception e) {
                    sender.sendMessage(ChatColor.RED + "Must be Number Value");
                }
            }
            sender.sendMessage("SKDEBUG = " + SkullTurret.DEBUG);
        }
        else if (cmd.getName().equalsIgnoreCase("skgive") && plugin.hasPermission(player, "skullturret.give")) {
            if (args.length != 1) {
                sender.sendMessage(ChatColor.RED + "Not enough args.");
                return false;
            }
            else {
                String name = args[0];
                if (name.equalsIgnoreCase("crazed")) {
                    ItemStack is = plugin.getCrazedSkull();
                    player.getInventory().addItem(is);
                }
                else if (name.equalsIgnoreCase("devious")) {
                    ItemStack is = plugin.getDeviousSkull();
                    player.getInventory().addItem(is);
                }
                else if (name.equalsIgnoreCase("master")) {
                    ItemStack is = plugin.getMasterSkull();
                    player.getInventory().addItem(is);
                }
                else if (name.equalsIgnoreCase("wizard")) {
                    ItemStack is = plugin.getWizardSkull();
                    player.getInventory().addItem(is);
                }
                else if (name.equalsIgnoreCase("bow")) {
                    ItemStack is = plugin.getSkullBow();
                    player.getInventory().addItem(is);
                }
                else {
                    sender.sendMessage(ChatColor.RED + "Unknown item type.");
                    return false;
                }
            }
        }
        else if (cmd.getName().equalsIgnoreCase("skaddfriend") && plugin.hasPermission(player, "skullturret.edit")) {
            if (cp.pc == null) {
                sender.sendMessage(ChatColor.RED + "You must click a skull first");
                return true;
            }
            if (SkullTurret.ONLYBOW) {
                player.sendMessage(ChatColor.RED + "Skulls are set to only target using the Skull Bow.");
                return false;
            }
            if (cp.pc.getIntelligence() == SkullIntelligence.CRAZED || cp.pc.getIntelligence() == SkullIntelligence.DEVIOUS) {
                player.sendMessage(ChatColor.RED + "You cant change targets for this skull.");
                return false;
            }
            if (args.length == 1) {
                if (args[0].toLowerCase().contains("monster") || args[0].toLowerCase().contains("animal")) {
                    cp.pc.friends.putAll(customTypes(args[0]));
                    sender.sendMessage(ChatColor.GOLD + args[0] + ChatColor.GREEN + " Added to Friends list of " + ChatColor.GOLD + cp.pc.getIntelligence().getNormalName() + ChatColor.GREEN + " Skull at " + ChatColor.GOLD + cp.pc.getStringLocation());
                    ds.saveDatabase(false);
                    return true;
                }
                else {
                    try {
                        EntityType type = EntityType.valueOf(args[0].toUpperCase());
                        cp.pc.friends.put(type, type);
                        String typeName = getName(type.name());
                        if (typeName == null) typeName = type.name();
                        sender.sendMessage(ChatColor.GOLD + typeName + ChatColor.GREEN + " Added to Friends list of " + ChatColor.GOLD + cp.pc.getIntelligence().getNormalName() + ChatColor.GREEN + " Skull at " + ChatColor.GOLD + cp.pc.getStringLocation());
                        ds.saveDatabase(false);
                    } catch (Exception e) {
                        sender.sendMessage(ChatColor.RED + "Not a valid entity Type");
                        return false;
                    }
                }
            }
            else if (args.length == 2) {
                try {
                    EntityType type = EntityType.valueOf(args[0].toUpperCase());
                    if (type == EntityType.PLAYER) {
                        if (cp.pc.getSkullCreator().equals(args[1]) || (cp.pc.playerFrenemies.containsKey(args[1]) && cp.pc.playerFrenemies.get(args[1]).equals("FRIEND"))) {
                            sender.sendMessage(ChatColor.GOLD + args[1] + ChatColor.RED + " is already in the friends list.");
                            return true;
                        }
                        if (cp.pc.getIntelligence() == SkullIntelligence.CRAZED || cp.pc.getIntelligence() == SkullIntelligence.DEVIOUS) {
                            player.sendMessage(ChatColor.RED + "You cant change targets for this skull.");
                            return false;
                        }
                        if (!cp.pc.playerFrenemies.containsKey(args[1])) {
                            cp.pc.playerFrenemies.put(args[1], "FRIEND");
                            String typeName = getName(type.name());
                            if (typeName == null) typeName = type.name();
                            sender.sendMessage(ChatColor.GOLD + typeName + " " + args[1] + ChatColor.GREEN + " Added to Friends list of " + ChatColor.GOLD + cp.pc.getIntelligence().getNormalName() + ChatColor.GREEN + " Skull at " + ChatColor.GOLD + cp.pc.getStringLocation());
                            ds.saveDatabase(false);
                            return true;
                        }
                        else {
                            sender.sendMessage(ChatColor.GOLD + args[1] + ChatColor.RED + " Already a " + ChatColor.GOLD + cp.pc.playerFrenemies.get(args[1]) + ChatColor.RED + " of " + ChatColor.GOLD + cp.pc.getIntelligence().getNormalName() + ChatColor.RED + " Skull at " + ChatColor.GOLD + cp.pc.getStringLocation());
                            return true;
                        }
                    }
                    else {
                        sender.sendMessage(ChatColor.RED + "Incorrect args for this command");
                        return false;
                    }
                } catch (Exception e) {
                    sender.sendMessage(ChatColor.RED + "Not a valid entity Type");
                    return false;
                }
            }
        }
        else if (cmd.getName().equalsIgnoreCase("skremfriend") && plugin.hasPermission(player, "skullturret.edit")) {
            if (cp.pc == null) {
                sender.sendMessage(ChatColor.RED + "You must click a skull first");
                return true;
            }
            if (SkullTurret.ONLYBOW) {
                player.sendMessage(ChatColor.RED + "Skulls are set to only target using the Skull Bow.");
                return false;
            }
            if (cp.pc.getIntelligence() == SkullIntelligence.CRAZED || cp.pc.getIntelligence() == SkullIntelligence.DEVIOUS) {
                player.sendMessage(ChatColor.RED + "You cant change targets for this skull.");
                return false;
            }
            if (args.length == 1) {
                try {
                    EntityType type = EntityType.valueOf(args[0].toUpperCase());
                    cp.pc.friends.remove(type);
                    String typeName = getName(type.name());
                    if (typeName == null) typeName = type.name();
                    sender.sendMessage(ChatColor.GOLD + typeName + ChatColor.AQUA + " Removed from Friends list of " + ChatColor.GOLD + cp.pc.getIntelligence().getNormalName() + ChatColor.AQUA + " Skull at " + ChatColor.GOLD + cp.pc.getStringLocation());
                    ds.saveDatabase(false);
                } catch (Exception e) {
                    sender.sendMessage(ChatColor.RED + "Not a valid entity Type");
                    return false;
                }
            }
            else if (args.length == 2) {
                try {
                    EntityType type = EntityType.valueOf(args[0].toUpperCase());
                    if (type == EntityType.PLAYER) {
                        if (cp.pc.getSkullCreator().equals(args[1])) {
                            sender.sendMessage(ChatColor.RED + "You cant be removed as a friend of your own skull.");
                            return true;
                        }
                        if (cp.pc.getIntelligence() == SkullIntelligence.CRAZED || cp.pc.getIntelligence() == SkullIntelligence.DEVIOUS) {
                            player.sendMessage(ChatColor.RED + "You cant change targets for this skull.");
                            return false;
                        }
                        if (cp.pc.playerFrenemies.containsKey(args[1])) {
                            cp.pc.playerFrenemies.remove(args[1]);
                            String typeName = getName(type.name());
                            if (typeName == null) typeName = type.name();
                            sender.sendMessage(ChatColor.GOLD + typeName + " " + args[1] + ChatColor.AQUA + " Removed from Friends list of " + ChatColor.GOLD + cp.pc.getIntelligence().getNormalName() + ChatColor.AQUA + " Skull at " + ChatColor.GOLD + cp.pc.getStringLocation());
                            ds.saveDatabase(false);
                            return true;
                        }
                        else {
                            sender.sendMessage(ChatColor.GOLD + args[1] + ChatColor.RED + " not a Friend of " + ChatColor.GOLD + cp.pc.getIntelligence().getNormalName() + ChatColor.RED + " Skull at " + ChatColor.GOLD + cp.pc.getStringLocation());
                            return true;
                        }
                    }
                    else {
                        sender.sendMessage(ChatColor.RED + "Incorrect args for this command");
                        return false;
                    }
                } catch (Exception e) {
                    sender.sendMessage(ChatColor.RED + "Not a valid entity Type");
                    return false;
                }
            }
        }
        else if (cmd.getName().equalsIgnoreCase("skaddenemy") && plugin.hasPermission(player, "skullturret.edit")) {
            if (cp.pc == null) {
                sender.sendMessage(ChatColor.RED + "You must click a skull first");
                return true;
            }
            if (SkullTurret.ONLYBOW) {
                player.sendMessage(ChatColor.RED + "Skulls are set to only target using the Skull Bow.");
                return false;
            }
            if (cp.pc.getIntelligence() == SkullIntelligence.CRAZED || cp.pc.getIntelligence() == SkullIntelligence.DEVIOUS) {
                player.sendMessage(ChatColor.RED + "You cant change targets for this skull.");
                return false;
            }
            if (args.length == 1) {
                if (args[0].toLowerCase().contains("monster") || args[0].toLowerCase().contains("animal")) {
                    cp.pc.enemies.putAll(customTypes(args[0]));
                    sender.sendMessage(ChatColor.GOLD + args[0] + ChatColor.GREEN + " Added to Enemies list of " + ChatColor.GOLD + cp.pc.getIntelligence().getNormalName() + ChatColor.GREEN + " Skull at " + ChatColor.GOLD + cp.pc.getStringLocation());
                    ds.saveDatabase(false);
                }
                else {
                    try {
                        EntityType type = EntityType.valueOf(args[0].toUpperCase());
                        cp.pc.enemies.put(type, type);
                        String typeName = getName(type.name());
                        if (typeName == null) typeName = type.name();
                        sender.sendMessage(ChatColor.GOLD + typeName + ChatColor.GREEN + " Added to Enemies list of " + ChatColor.GOLD + cp.pc.getIntelligence().getNormalName() + ChatColor.GREEN + " Skull at " + ChatColor.GOLD + cp.pc.getStringLocation());
                        ds.saveDatabase(false);
                    } catch (Exception e) {
                        sender.sendMessage(ChatColor.RED + "Not a valid entity Type");
                        return false;
                    }
                }
            }
            else if (args.length == 2) {
                try {
                    EntityType type = EntityType.valueOf(args[0].toUpperCase());
                    if (type == EntityType.PLAYER) {
                        if (cp.pc.getSkullCreator().equals(args[1])) {
                            sender.sendMessage(ChatColor.RED + "You cant be an enemy of your own skulls.");
                            return true;
                        }
                        if (cp.pc.getIntelligence() == SkullIntelligence.CRAZED || cp.pc.getIntelligence() == SkullIntelligence.DEVIOUS) {
                            player.sendMessage(ChatColor.RED + "You cant change targets for this skull.");
                            return false;
                        }
                        if (!cp.pc.playerFrenemies.containsKey(args[1])) {
                            cp.pc.playerFrenemies.put(args[1], "ENEMY");
                            String typeName = getName(type.name());
                            if (typeName == null) typeName = type.name();
                            sender.sendMessage(ChatColor.GOLD + typeName + " " + args[1] + ChatColor.GREEN + " Added to Enemies list of " + ChatColor.GOLD + cp.pc.getIntelligence().getNormalName() + ChatColor.GREEN + " Skull at " + ChatColor.GOLD + cp.pc.getStringLocation());
                            ds.saveDatabase(false);
                        }
                        else {
                            sender.sendMessage(ChatColor.GOLD + args[1] + ChatColor.RED + " Already a " + ChatColor.GOLD + cp.pc.playerFrenemies.get(args[1]) + ChatColor.RED + " of " + ChatColor.GOLD + cp.pc.getIntelligence().getNormalName() + ChatColor.RED + " Skull at " + ChatColor.GOLD + cp.pc.getStringLocation());
                            return true;
                        }
                    }
                    else {
                        sender.sendMessage(ChatColor.RED + "Incorrect args for this command");
                        return false;
                    }
                } catch (Exception e) {
                    sender.sendMessage(ChatColor.RED + "Not a valid entity Type");
                    return false;
                }
            }
        }
        else if (cmd.getName().equalsIgnoreCase("skremenemy") && plugin.hasPermission(player, "skullturret.edit")) {
            if (cp.pc == null) {
                sender.sendMessage(ChatColor.RED + "You must click a skull first");
                return true;
            }
            if (SkullTurret.ONLYBOW) {
                player.sendMessage(ChatColor.RED + "Skulls are set to only target using the Skull Bow.");
                return false;
            }
            if (cp.pc.getIntelligence() == SkullIntelligence.CRAZED || cp.pc.getIntelligence() == SkullIntelligence.DEVIOUS) {
                player.sendMessage(ChatColor.RED + "You cant change targets for this skull.");
                return false;
            }
            if (args.length == 1) {
                try {
                    EntityType type = EntityType.valueOf(args[0].toUpperCase());
                    cp.pc.enemies.remove(type);
                    String typeName = getName(type.name());
                    if (typeName == null) typeName = type.name();
                    sender.sendMessage(ChatColor.GOLD + typeName + ChatColor.AQUA + " Removed from Enemies list of " + ChatColor.GOLD + cp.pc.getIntelligence().getNormalName() + ChatColor.AQUA + " Skull at " + ChatColor.GOLD + cp.pc.getStringLocation());
                    ds.saveDatabase(false);
                } catch (Exception e) {
                    sender.sendMessage(ChatColor.RED + "Not a valid entity Type");
                    return false;
                }
            }
            else if (args.length == 2) {
                try {
                    EntityType type = EntityType.valueOf(args[0].toUpperCase());
                    if (type == EntityType.PLAYER) {
                        if (cp.pc.getSkullCreator().equals(args[1])) {
                            sender.sendMessage(ChatColor.RED + "You are not an enemy of your own skulls.");
                            return true;
                        }
                        if (cp.pc.getIntelligence() == SkullIntelligence.CRAZED || cp.pc.getIntelligence() == SkullIntelligence.DEVIOUS) {
                            player.sendMessage(ChatColor.RED + "You cant change targets for this skull.");
                            return false;
                        }
                        if (cp.pc.playerFrenemies.containsKey(args[1])) {
                            cp.pc.playerFrenemies.remove(args[1]);
                            String typeName = getName(type.name());
                            if (typeName == null) typeName = type.name();
                            sender.sendMessage(ChatColor.GOLD + typeName + " " + args[1] + ChatColor.AQUA + " Removed from Enemies list of " + ChatColor.GOLD + cp.pc.getIntelligence().getNormalName() + ChatColor.AQUA + " Skull at " + ChatColor.GOLD + cp.pc.getStringLocation());
                            ds.saveDatabase(false);
                            return true;
                        }
                        else {
                            sender.sendMessage(ChatColor.GOLD + args[1] + ChatColor.RED + " not a Enemy of " + ChatColor.GOLD + cp.pc.getIntelligence().getNormalName() + ChatColor.RED + " Skull at " + ChatColor.GOLD + cp.pc.getStringLocation());
                            return true;
                        }
                    }
                    else {
                        sender.sendMessage(ChatColor.RED + "Incorrect args for this command");
                        return false;
                    }
                } catch (Exception e) {
                    sender.sendMessage(ChatColor.RED + "Not a valid entity Type");
                    return false;
                }
            }
        }
        else if (cmd.getName().equalsIgnoreCase("skedit") && plugin.hasPermission(player, "skullturret.edit")) {
            cp.command = "skedit";
            sender.sendMessage(ChatColor.AQUA + "Click a skull to select for editing.");
        }
        else if (cmd.getName().equalsIgnoreCase("skdone") && plugin.hasPermission(player, "skullturret.edit")) {
            cp.clearPlayer();
            sender.sendMessage(ChatColor.YELLOW + "Finished editing Skulls.");
        }
        else if (cmd.getName().equalsIgnoreCase("skpatrol") && plugin.hasPermission(player, "skullturret.edit")) {
            if (cp.pc == null) {
                sender.sendMessage(ChatColor.RED + "You must click a skull first");
                return true;
            }
            cp.pc.setPatrol(!cp.pc.doPatrol());
            sender.sendMessage(ChatColor.AQUA + "This Skull " + (cp.pc.doPatrol() ? ChatColor.GREEN + "will" : ChatColor.RED + "wont") + ChatColor.AQUA + " patrol.");
        }
        else if (cmd.getName().equalsIgnoreCase("skrotate") && plugin.hasPermission(player, "skullturret.edit")) {
            if (cp.command.equals("skroate")) {
                cp.clearPlayer();
                sender.sendMessage(ChatColor.YELLOW + "Rotation command canceled.");
                return true;
            }
            cp.command = "skrotate";
            sender.sendMessage(ChatColor.AQUA + "Click Skull to rotate.");
        }
        else if (cmd.getName().equalsIgnoreCase("skredstone") && plugin.hasPermission(player, "skullturret.edit")) {
            if (cp.pc == null) {
                sender.sendMessage(ChatColor.RED + "You must click a skull first");
                return true;
            }
            cp.pc.setRedstone(!cp.pc.isRedstone());
            sender.sendMessage(ChatColor.AQUA + "This Skull " + (cp.pc.isRedstone() ? ChatColor.GREEN + "will" : ChatColor.RED + "wont") + ChatColor.AQUA + " listen to redstone signals.");
        }
        else if (cmd.getName().equalsIgnoreCase("skammo") && plugin.hasPermission(player, "skullturret.changeammo")) {
            if (cp.pc == null) {
                sender.sendMessage(ChatColor.RED + "You must click a skull first");
                return true;
            }
            if (args.length == 1) {
                if (cp.pc.getIntelligence() != SkullIntelligence.WIZARD) {
                    EntityType ammo = getAmmoType(cp.pc, args[0]);
                    if (ammo != null) {
                        cp.pc.setAmmoType(ammo);
                        sender.sendMessage(ChatColor.GREEN + "Ammo type changed to " + ChatColor.GOLD + args[0].toUpperCase());
                    }
                    else {
                        sender.sendMessage(ChatColor.RED + "Not a valid ammo type: " + ChatColor.GOLD + "arrow, firearrow, firecharge, snowball");
                    }
                }
                else {
                    sender.sendMessage(ChatColor.GOLD + cp.pc.getIntelligence().getNormalName() + ChatColor.RED + " Skulls can not change their ammo type.");
                }
            }
            else {
                sender.sendMessage(ChatColor.RED + "Not a valid ammo type: Arrow, firearrow, firecharge, snowball");
                return true;
            }
        }
        else if (cmd.getName().equalsIgnoreCase("skaddplayer") && plugin.hasPermission(player, "skullturret.addplayer")) {
            if (args.length == 3) {
                try {
                    String playerName = args[0];
                    int maxTurret = Integer.parseInt(args[1]);
                    int maxRange = Integer.parseInt(args[2]);
                    if (maxRange % 3 == 0) {
                        PerPlayerSettings perPlayerSettings = new PerPlayerSettings(playerName, maxTurret, maxRange);
                        boolean contained = plugin.pps.containsKey(playerName);
                        plugin.pps.put(playerName, perPlayerSettings);
                        ds.savePerPlayerSettings();
                        sender.sendMessage(ChatColor.GRAY + "Player: " + ChatColor.GOLD + playerName + ChatColor.GRAY + " MaxTurrets: " + ChatColor.GOLD + maxTurret + ChatColor.GRAY + " MaxRange: " + ChatColor.GOLD + maxRange);
                        if (!contained)
                            sender.sendMessage(ChatColor.GREEN + "Added player to list.");
                        else
                            sender.sendMessage(ChatColor.YELLOW + "Updated player in list.");
                    }
                    else {
                        sender.sendMessage(ChatColor.RED + "Bad Range Value for " + playerName);
                        sender.sendMessage(ChatColor.GOLD + "" + maxRange + ChatColor.RED + " Not a Multiple of 3.");
                        sender.sendMessage(ChatColor.RED + "Not added to list.");
                        return true;
                    }
                } catch (Exception e) {
                    sender.sendMessage(ChatColor.RED + "Invalid arguments");
                    return false;
                }
            }
            else {
                sender.sendMessage(ChatColor.RED + "Incorrect args for this command");
                return false;
            }
        }
        else if (cmd.getName().equalsIgnoreCase("skremplayer") && plugin.hasPermission(player, "skullturret.remplayer") && SkullTurret.PERPLAYERSETTINGS) {
            if (args.length == 1) {
                String playerName = args[0];
                boolean contained = plugin.pps.containsKey(playerName);
                if (!contained) {
                    sender.sendMessage(ChatColor.RED + "Player not found in list.");
                }
                else {
                    plugin.pps.remove(playerName);
                    sender.sendMessage(ChatColor.AQUA + "Removed player " + ChatColor.GOLD + playerName + ChatColor.AQUA + " from list.");
                    ds.savePerPlayerSettings();
                }
            }
            else {
                sender.sendMessage(ChatColor.RED + "Incorrect args for this command");
                return false;
            }
        }
        else if (cmd.getName().equalsIgnoreCase("sklistallplayer") && plugin.hasPermission(player, "skullturret.listallplayer") && SkullTurret.PERPLAYERSETTINGS) {
            if (plugin.pps.size() == 0) {
                sender.sendMessage(ChatColor.YELLOW + "No custom players settings found.");
                return true;
            }
            sender.sendMessage(ChatColor.AQUA + "Skull Turret Custom Player List");
            sender.sendMessage(ChatColor.AQUA + "*******************************");
            for(PerPlayerSettings p : plugin.pps.values()) {
                String playerName = p.getPlayerName();
                int maxRange = p.getMaxRange();
                int maxTurret = p.getMaxTurrets();
                sender.sendMessage(ChatColor.GRAY + "Player: " + ChatColor.GREEN + playerName + ChatColor.GRAY + " MaxTurrets: " + ChatColor.GREEN + maxTurret + ChatColor.GRAY + " MaxRange: " + ChatColor.GREEN + maxRange);
            }
        }
        else if (cmd.getName().equalsIgnoreCase("sklistplayer") && plugin.hasPermission(player, "skullturret.listplayer") && SkullTurret.PERPLAYERSETTINGS) {
            if (plugin.pps.size() == 0 || !plugin.pps.containsKey(sender.getName())) {
                sender.sendMessage(ChatColor.YELLOW + "Not in custom players list.");
                return true;
            }
            sender.sendMessage(ChatColor.AQUA + "Skull Turret Custom Player List");
            sender.sendMessage(ChatColor.AQUA + "*******************************");
            String playerName = plugin.pps.get(sender.getName()).getPlayerName();
            int maxRange = plugin.pps.get(sender.getName()).getMaxRange();
            int maxTurret = plugin.pps.get(sender.getName()).getMaxTurrets();
            sender.sendMessage(ChatColor.GRAY + "Player: " + ChatColor.GOLD + playerName + ChatColor.GRAY + " MaxTurrets: " + ChatColor.GOLD + maxTurret + ChatColor.GRAY + " MaxRange: " + ChatColor.GOLD + maxRange);
        }
        else if (cmd.getName().equalsIgnoreCase("skreload") && (plugin.hasPermission(player, "skullturret.admin") || plugin.hasPermission(player, "skullturret.reload"))) {
            if (cp.command.equals("RELOAD") && (args.length == 0 || (args.length > 0 && args[0].equalsIgnoreCase("no")))) {
                cp.clearPlayer();
                sender.sendMessage(ChatColor.GREEN + plugin.pluginName + ": Datafile reload canceled.");
            }
            else if (cp.command.equals("RELOAD") && (args.length > 0 && args[0].equalsIgnoreCase("yes"))) {
                sender.sendMessage(ChatColor.GREEN + plugin.pluginName + ": Datafiles reloading.");
                SkullTurret.RELOAD = true;
                ds.reInit();
                sender.sendMessage(ChatColor.GOLD + plugin.pluginName + ": Finished reloading, check server log for info.");
                cp.clearPlayer();
                return true;
            }
            else {
                cp.command = "RELOAD";
                sender.sendMessage(ChatColor.YELLOW + plugin.pluginName + ": " + ChatColor.UNDERLINE + "Caution!" + ChatColor.RESET + ChatColor.YELLOW + " Datafile reloading can cause temporary server lag if a");
                sender.sendMessage(ChatColor.YELLOW + plugin.pluginName + ": large number of skulls are in play.");
                sender.sendMessage(ChatColor.YELLOW + plugin.pluginName + ": Use: " + ChatColor.GREEN + "/skreload yes " + ChatColor.YELLOW + "to confirm or " + ChatColor.GREEN + "/skreload no " + ChatColor.YELLOW + "to cancel.");
            }
        }
        return true;
    }
    
     private boolean inConsoleLegacyCommands(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        if (cmd.getName().equalsIgnoreCase("skaddplayer")) {
            if (args.length == 3) {
                try {
                    String playerName = args[0];
                    int maxTurret = Integer.parseInt(args[1]);
                    int maxRange = Integer.parseInt(args[2]);
                    if (maxRange % 3 == 0) {
                        PerPlayerSettings perPlayerSettings = new PerPlayerSettings(playerName, maxTurret, maxRange);
                        boolean contained = plugin.pps.containsKey(playerName);
                        plugin.pps.put(playerName, perPlayerSettings);
                        ds.savePerPlayerSettings();
                        sender.sendMessage(ChatColor.GRAY + "Player: " + ChatColor.GOLD + playerName + ChatColor.GRAY + " MaxTurrets: " + ChatColor.GOLD + maxTurret + ChatColor.GRAY + " MaxRange: " + ChatColor.GOLD + maxRange);
                        if (!contained)
                            sender.sendMessage(ChatColor.GREEN + "Added player to list.");
                        else
                            sender.sendMessage(ChatColor.YELLOW + "Updated player in list.");
                    }
                    else {
                        sender.sendMessage(ChatColor.RED + "Bad Range Value for " + playerName);
                        sender.sendMessage(ChatColor.GOLD + "" + maxRange + ChatColor.RED + " Not a Multiple of 3.");
                        sender.sendMessage(ChatColor.RED + "Not added to list.");
                        return true;
                    }
                } catch (Exception e) {
                    sender.sendMessage(ChatColor.RED + "Invalid arguments");
                    return false;
                }
            }
            else {
                sender.sendMessage(ChatColor.RED + "Incorrect args for this command");
                return false;
            }
        }
        else if (cmd.getName().equalsIgnoreCase("skremplayer") && SkullTurret.PERPLAYERSETTINGS) {
            if (args.length == 1) {
                String playerName = args[0];
                boolean contained = plugin.pps.containsKey(playerName);
                if (!contained) {
                    sender.sendMessage(ChatColor.RED + "Player not found in list.");
                }
                else {
                    plugin.pps.remove(playerName);
                    sender.sendMessage(ChatColor.AQUA + "Removed player " + ChatColor.GOLD + playerName + ChatColor.AQUA + " from list.");
                    ds.savePerPlayerSettings();
                }
            }
            else {
                sender.sendMessage(ChatColor.RED + "Incorrect args for this command");
                return false;
            }
        }
        else if (cmd.getName().equalsIgnoreCase("sklistallplayer") && SkullTurret.PERPLAYERSETTINGS) {
            if (plugin.pps.size() == 0) {
                sender.sendMessage(ChatColor.YELLOW + "No custom players settings found.");
                return true;
            }
            sender.sendMessage(ChatColor.AQUA + "Skull Turret Custom Player List");
            sender.sendMessage(ChatColor.AQUA + "*******************************");
            for(PerPlayerSettings p : plugin.pps.values()) {
                String playerName = p.getPlayerName();
                int maxRange = p.getMaxRange();
                int maxTurret = p.getMaxTurrets();
                sender.sendMessage(ChatColor.GRAY + "Player: " + ChatColor.GOLD + playerName + ChatColor.GRAY + " MaxTurrets: " + ChatColor.GOLD + maxTurret + ChatColor.GRAY + " MaxRange: " + ChatColor.GOLD + maxRange);
            }
        }
        else if (cmd.getName().equalsIgnoreCase("skreload")) {
            if (SkullTurret.RELOADQUESTION && (args.length == 0 || (args.length > 0 && args[0].equalsIgnoreCase("no")))) {
                SkullTurret.RELOADQUESTION = false;
                sender.sendMessage(ChatColor.GREEN + plugin.pluginName + ": Datafile reload canceled.");
            }
            else if (SkullTurret.RELOADQUESTION && (args.length > 0 && args[0].equalsIgnoreCase("yes"))) {
                sender.sendMessage(ChatColor.GREEN + plugin.pluginName + ": Datafiles reloading.");
                SkullTurret.RELOAD = true;
                ds.reInit();
                sender.sendMessage(ChatColor.GOLD + plugin.pluginName + ": Finished reloading.");
                SkullTurret.RELOADQUESTION = false;
                return true;
            }
            else {
                SkullTurret.RELOADQUESTION = true;
                sender.sendMessage(ChatColor.YELLOW + plugin.pluginName + ": -----");
                sender.sendMessage(ChatColor.UNDERLINE + "Caution!" + ChatColor.RESET + ChatColor.YELLOW + " Datafile reloading can cause temporary");
                sender.sendMessage(ChatColor.YELLOW + "server lag if a large number of skulls are in play.");
                sender.sendMessage(ChatColor.YELLOW + "Use: " + ChatColor.GREEN + "skreload yes " + ChatColor.YELLOW + "to confirm or " + ChatColor.GREEN + "skreload no " + ChatColor.YELLOW + "to cancel.");
            }
        }
        return true;
    }

 if (!potentialTarget.hasLineOfSight(entity)) {
            if (SkullTurret.DEBUG == 1)
                System.out.println("No line of sight " + potentialTarget.getType().getName() + " int = " + intelligence.getNormalName());
            entity.remove();
            if (potentialTarget instanceof Player) { //TODO Bukkit lineOfSight Bug Workaround
                try {
                    Vector start = skullLoc.toVector();
                    BlockIterator lineOfSight = new BlockIterator(world, start, direction, 0, (int) fireRange);
                    while (lineOfSight.hasNext()) {
                        Block b = lineOfSight.next();
                        if (b.equals(targetLoc.getBlock())) break;
                        if (b.getLocation().equals(getLocation())) continue;
                        if (!b.getType().equals(Material.AIR)) return null;
                    }
                    return vect;
                } catch (Exception e) {
                    return null;
                }
            }
            else {
                return null;
            }
        }
        else if (SkullTurret.ALLOWFRIENDLYFIRE) {
            entity.remove();
            return vect;
        }

        if (SkullTurret.DEBUG == 1) {
            if (!plugin.hasPermission(player, "skullturret.debug")) { //TODO
                player.sendMessage(ChatColor.RED + "Sorry you dont have permissions.");
                event.setCancelled(true);
                return;
            }

            if (cp.pc != null && event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                cp.pc.manualFire(player, EntityType.SNOWBALL);
            }
        }
        else 

    public void manualFire(LivingEntity target, EntityType ammoType) {
        rotate(target);
        this.target = target;
        Location skullLoc = getAxisAlignment();
        Location targetLoc = new Location(world, target.getLocation().getX(), target.getLocation().getY() + 1, target.getLocation().getZ());
        Vector toTarget = targetLoc.toVector().subtract(skullLoc.toVector());
        double speed = 1.5;
        double d0 = toTarget.getX();
        double d1 = toTarget.getY();
        double d2 = toTarget.getZ();
        float f2 = (float) Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);

        d0 /= f2;
        d1 /= f2;
        d2 /= f2;
        d0 *= speed;
        d1 *= speed;
        d2 *= speed;
        Vector vect = new Vector(d0, d1, d2);
        Entity e = world.spawnEntity(skullLoc, ammoType);
        if (e != null)
            e.setVelocity(vect);
    }

    @SuppressWarnings("unused")
    private BlockFace getRotationBlockFace(int dirId) {
        switch (dirId) {
            case 0:
                return BlockFace.NORTH;
            case 1:
                return BlockFace.NORTH_NORTH_EAST;
            case 2:
                return BlockFace.NORTH_EAST;
            case 3:
                return BlockFace.EAST_NORTH_EAST;
            case 4:
                return BlockFace.EAST;
            case 5:
                return BlockFace.EAST_SOUTH_EAST;
            case 6:
                return BlockFace.SOUTH_EAST;
            case 7:
                return BlockFace.SOUTH_SOUTH_EAST;
            case 8:
                return BlockFace.SOUTH;
            case 9:
                return BlockFace.SOUTH_SOUTH_WEST;
            case 10:
                return BlockFace.SOUTH_WEST;
            case 11:
                return BlockFace.WEST_SOUTH_WEST;
            case 12:
                return BlockFace.WEST;
            case 13:
                return BlockFace.WEST_NORTH_WEST;
            case 14:
                return BlockFace.NORTH_WEST;
            case 15:
                return BlockFace.NORTH_NORTH_WEST;
            default:
                return BlockFace.NORTH;
        }
    }

        /*else if (cmd.getName().equalsIgnoreCase("skrange") && hasPermission(player, "skullturret.debug")) {
            if (cp.pc == null) {
                sender.sendMessage(ChatColor.RED + "You must click a skull first");
                return true;
            }
            if (args.length == 1) {
                try {
                    int range = Integer.parseInt(args[0]);
                    cp.pc.setMaxRange(range);
                    double fireRange = cp.pc.getMaxRange() * cp.pc.getIntelligence().getFireRangeMultiplier();
                    cp.pc.setFireRange(fireRange);
                    sender.sendMessage("Range set to " + range + " for " + cp.pc.getIntelligence().getNormalName() + " Skull at " + cp.pc.getStringLocation());
                    cp.pc.reInitSkull();
                    ds.saveDatabase(false);
                } catch (Exception e) {
                    sender.sendMessage(ChatColor.RED + "Not a valid range");
                    return false;
                }
            }
        }*/

    private void loadPlayerRanges() {
        Map<String, Integer> customRanges = new HashMap<String, Integer>();
        List<String> ranges = plugin.getConfig().getStringList("custom_ranges");
        try {
            for(String s : ranges) {
                String playerName = s.split(",")[0];
                int r = getMaxRange(playerName, Integer.parseInt(s.split(",")[1]));
                customRanges.put(playerName, r);
            }
        } catch (Exception e) {
            SkullTurret.LOGGER.warning(SkullTurret.plugin.pluginName + ": There was a parsing error in the Custom Ranges!");
        }
        if (customRanges.size() > 0)
            SkullTurret.plugin.playerRanges.putAll(customRanges);
    }

        else if (cmd.getName().equalsIgnoreCase("skdrop") && hasPermission(player, "skullturret.debug")) { //TODO Remove command later
            if (DROP)
                DROP = false;
            else
                DROP = true;
            sender.sendMessage("SKDROP = " + DROP);
        }
        else if (cmd.getName().equalsIgnoreCase("skfire") && hasPermission(player, "skullturret.debug")) { //TODO Remove command later
            if (cp.pc == null && args.length == 0) {
                sender.sendMessage(ChatColor.RED + "You must click a skull first");
                return true;
            }
            else {
                if (args.length == 1) {
                    boolean holdFire = !Boolean.parseBoolean(args[0]);
                    for(PlacedSkull pc : skullMap.values()) {
                        pc.holdFire = holdFire;
                    }
                    sender.sendMessage(ChatColor.YELLOW + (holdFire ? "Holding Fire!" : "Firing!"));
                    return true;
                }
            }
            cp.pc.manualFire((Player) sender, EntityType.SNOWBALL);
            sender.sendMessage(ChatColor.YELLOW + "Firing!");
        }
        else if (cmd.getName().equalsIgnoreCase("skclear") && hasPermission(player, "skullturret.debug")) { //TODO Removed command later
            cp.clearPlayer();
            sender.sendMessage(ChatColor.GOLD + "Skull selection cleared.");
            return true;
        }

             skX:
    description: Toggles the skulls ability to listen for redstone power
    permission: skullturret.edit
    usage: |
      /<command> - Toggles the skulls ability to listen for redstone power
  skY:
    description: Toggles the skulls ability to listen for redstone power
    permission: skullturret.edit
    usage: |
      /<command> - Toggles the skulls ability to listen for redstone power
  skZ:
    description: Toggles the skulls ability to listen for redstone power
    permission: skullturret.edit
    usage: |
      /<command> - Toggles the skulls ability to listen for redstone power
           
           else if(cmd.getName().equals("skX")){
            if (cp.pc == null) {
                sender.sendMessage(ChatColor.RED + "You must click a skull first");
                return true;
            }
            tempX = Double.parseDouble(args[0]);
        }
        else if(cmd.getName().equals("skY")){
            if (cp.pc == null) {
                sender.sendMessage(ChatColor.RED + "You must click a skull first");
                return true;
            }
            tempY = Double.parseDouble(args[0]);
        }
        else if(cmd.getName().equals("skZ")){
            if (cp.pc == null) {
                sender.sendMessage(ChatColor.RED + "You must click a skull first");
                return true;
            }
            tempZ = Double.parseDouble(args[0]);
        }
   
    public Location debugAxisAlignment() {
        return getAxisAlignment();
    }
   
    private Location getTestAxisAlignment() {
        double x = centerX;
        double y = centerY;
        double z = centerZ;
        return new Location(world, x + SkullTurret.tempX, y + SkullTurret.tempY, z + SkullTurret.tempZ);
    }
   
   /*
        plugin.server.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { //TODO

            private Map<Entity, Long> axisMap = new HashMap<Entity, Long>();

            public void run() {
                long currentTime = System.currentTimeMillis();
                for(PlacedSkull skull : plugin.skullMap.values()) {
                    World world = skull.getLocation().getWorld();
                    Entity e = world.spawnEntity(skull.debugAxisAlignment(), EntityType.SNOWBALL);
                    axisMap.put(e, currentTime);
                }
                List<Entity> removes = new ArrayList<Entity>();
                for(Entry<Entity, Long> ent : axisMap.entrySet()) {
                    if (currentTime - ent.getValue() > 100) {
                        ent.getKey().remove();
                        removes.add(ent.getKey());
                    }
                }
                for(Entity e : removes) {
                    axisMap.remove(e);
                }
            }
        }, 5, 5);*/
   
    private Location getAxisAlignment() {
        double x = centerX;
        double y = centerY;
        double z = centerZ;
        switch (getSkull().getRotation()) {
            case NORTH:
                return new Location(world, x + 0.5, y + 0.2, z - 0.2);
            case NORTH_NORTH_EAST:
                return new Location(world, x + 0.8, y + 0.2, z - 0.05);
            case NORTH_EAST:
                return new Location(world, x + 1, y + 0.2, z + 0.06);
            case EAST_NORTH_EAST:
                return new Location(world, x + 1.1, y + 0.2, z + 0.31);
            case EAST:
                return new Location(world, x + 1.2, y + 0.2, z + 0.5);
            case EAST_SOUTH_EAST:
                return new Location(world, x + 1.1, y + 0.2, z + 0.8);
            case SOUTH_EAST:
                return new Location(world, x + 1, y + 0.2, z + 1);
            case SOUTH_SOUTH_EAST:
                return new Location(world, x + 0.8, y + 0.2, z + 1.1);
            case SOUTH:
                return new Location(world, x + 0.5, y + 0.2, z + 1.2);
            case SOUTH_SOUTH_WEST:
                return new Location(world, x + 0.31, y + 0.2, z + 1.1);
            case SOUTH_WEST:
                return new Location(world, x + 0.06, y + 0.2, z + 1);
            case WEST_SOUTH_WEST:
                return new Location(world, x - 0.05, y + 0.2, z + 0.8);
            case WEST:
                return new Location(world, x - 0.2, y + 0.2, z + 0.5);
            case WEST_NORTH_WEST:
                return new Location(world, x - 0.2, y + 0.2, z + 0.2);
            case NORTH_WEST:
                return new Location(world, x, y + 0.2, z);
            case NORTH_NORTH_WEST:
                return new Location(world, x + 0.2, y + 0.2, z - 0.2);
            default:
                return new Location(world, x, y + 0.2, z);
        }
    }
    
private void patrol() {
        long currentTime = System.currentTimeMillis();
        if (currentTime - rotUpdateTimer > 2000) {
            rotUpdateTimer = currentTime;
            Skull skull = getSkull();
            if (currentTime - rotTimer > 30000) {
                boolean clockWise = new Random().nextBoolean();
                if (clockWise)
                    dirMod = 1;
                else
                    dirMod = -1;
                rotTimer = currentTime;
            }
            BlockFace newRotationDir = skull.getRotation();
            if (currentRotDir > 15 && dirMod > 0)
                currentRotDir = 0;
            else if (currentRotDir < 0 && dirMod < 0)
                currentRotDir = 15;
            switch (currentRotDir) {
                case 0:
                    newRotationDir = BlockFace.NORTH_NORTH_EAST;
                    break;
                case 1:
                    newRotationDir = BlockFace.NORTH_EAST;
                    break;
                case 2:
                    newRotationDir = BlockFace.EAST_NORTH_EAST;
                    break;
                case 3:
                    newRotationDir = BlockFace.EAST;
                    break;
                case 4:
                    newRotationDir = BlockFace.EAST_SOUTH_EAST;
                    break;
                case 5:
                    newRotationDir = BlockFace.SOUTH_EAST;
                    break;
                case 6:
                    newRotationDir = BlockFace.SOUTH_SOUTH_EAST;
                    break;
                case 7:
                    newRotationDir = BlockFace.SOUTH;
                    break;
                case 8:
                    newRotationDir = BlockFace.SOUTH_SOUTH_WEST;
                    break;
                case 9:
                    newRotationDir = BlockFace.SOUTH_WEST;
                    break;
                case 10:
                    newRotationDir = BlockFace.WEST_SOUTH_WEST;
                    break;
                case 11:
                    newRotationDir = BlockFace.WEST;
                    break;
                case 12:
                    newRotationDir = BlockFace.WEST_NORTH_WEST;
                    break;
                case 13:
                    newRotationDir = BlockFace.NORTH_WEST;
                    break;
                case 14:
                    newRotationDir = BlockFace.NORTH_NORTH_WEST;
                    break;
                default:
                    newRotationDir = BlockFace.NORTH;
            }
            if (skull.getBlock().getRelative(newRotationDir).getType() != Material.AIR) {
                dirMod = -dirMod;
                coolDown = 0;
                rotTimer = currentTime;
                currentRotDir += dirMod + dirMod;
                return;//TODO
            }
            skull.setRotation(newRotationDir);
            if (SkullTurret.DEBUG == 1) skull.setOwner(skullOwnerData);
            skull.update(true);
            currentRotDir += dirMod;
        }
    }

if (block != null && plugin.skullMap.containsKey(block.getLocation()) && block.getType().equals(Material.SKULL) && event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
                PlacedSkull pc = plugin.skullMap.get(block.getLocation());
                Skull skull = pc.getSkull();
                skull.setRotation(rotation(skull));
                skull.update(true);
                String owner = pc.getOwner();
                SkullType type = pc.getType();
                if (!owner.equals(""))
                    skull.setOwner(owner);
                else
                    skull.setSkullType(type);
                skull.update(true);
                player.sendMessage(ChatColor.GREEN + "Skull Rotated to " + skull.getRotation().name());
            }
            else 
            
            private BlockFace rotation(Skull skull) {
        BlockFace face = skull.getRotation();
        switch (face) {
            case NORTH:
                return BlockFace.NORTH_NORTH_EAST;
            case NORTH_NORTH_EAST:
                return BlockFace.NORTH_EAST;
            case NORTH_EAST:
                return BlockFace.EAST_NORTH_EAST;
            case EAST_NORTH_EAST:
                return BlockFace.EAST;
            case EAST:
                return BlockFace.EAST_SOUTH_EAST;
            case EAST_SOUTH_EAST:
                return BlockFace.SOUTH_EAST;
            case SOUTH_EAST:
                return BlockFace.SOUTH_SOUTH_EAST;
            case SOUTH_SOUTH_EAST:
                return BlockFace.SOUTH;
            case SOUTH:
                return BlockFace.SOUTH_SOUTH_WEST;
            case SOUTH_SOUTH_WEST:
                return BlockFace.SOUTH_WEST;
            case SOUTH_WEST:
                return BlockFace.WEST_SOUTH_WEST;
            case WEST_SOUTH_WEST:
                return BlockFace.WEST;
            case WEST:
                return BlockFace.WEST_NORTH_WEST;
            case WEST_NORTH_WEST:
                return BlockFace.NORTH_WEST;
            case NORTH_WEST:
                return BlockFace.NORTH_NORTH_WEST;
            case NORTH_NORTH_WEST:
                return BlockFace.NORTH;
            default:
                return BlockFace.NORTH;
        }
    }

private Vector getFiringSolution(LivingEntity potentialTarget) {
        Vector vect = null;
        Location skullLoc = getAxisAlignment();
        Location targetLoc = new Location(world, potentialTarget.getLocation().getX(), potentialTarget.getLocation().getY() + potentialTarget.getEyeHeight(), potentialTarget.getLocation().getZ());
        Vector toTarget = targetLoc.toVector().subtract(skullLoc.toVector());
        double speed = fireRange * 0.25;
        double d0 = toTarget.getX();
        double d1 = toTarget.getY();
        double d2 = toTarget.getZ();
        float f2 = (float) Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);

        d0 /= f2;
        d1 /= f2;
        d2 /= f2;
        d0 *= speed;
        d1 *= speed;
        d2 *= speed;
        vect = new Vector(d0, d1, d2);
        Vector direction = vect;
        if (intelligence == SkullIntelligence.BASIC) return vect;

        Entity entity = world.spawnEntity(skullLoc, EntityType.EXPERIENCE_ORB);
        if (entity != null) {
            if (potentialTarget.hasLineOfSight(entity)) {
                entity.remove();
                return vect;
            }
            else {
                entity.remove();
                return null;
            }
        }
        else {
            try {
                Vector start = skullLoc.toVector();
                BlockIterator lineOfSight = new BlockIterator(world, start, direction, 0, (int) fireRange);
                while (lineOfSight.hasNext()) {
                    Block b = lineOfSight.next();
                    if (b.equals(potentialTarget.getLocation().getBlock())) break;
                    if (b.getLocation().equals(getLocation())) continue;
                    if (!b.getType().equals(Material.AIR)) return null;
                }
                return vect;
            } catch (Exception e) {
                return null;
            }
        }
    }

/*
            for(ChunkCoords cc : chunkList) {
                for(Entity e : world.getChunkAt(cc.x, cc.z).getEntities()) {
                    if (e instanceof LivingEntity && isInRange((LivingEntity) e) && !(e instanceof Player && ((Player) e).getName().equals(skullCreator))) {
                        List<MetadataValue> meta = e.getMetadata("SkullWatch");
                        if (meta.size() > 0) {
                            long time = meta.get(0).asLong();
                            if (currentTime - time > 5000)
                                e.removeMetadata("SkullWatch", SkullWatch.plugin);
                            else
                                continue;
                        }
                        Location entLoc = e.getLocation();
                        RangeCoord rc = new RangeCoord(world, entLoc.getBlockX(), centerY, entLoc.getBlockZ());
                        FacingRange fr = directions.get(rc);
                        if (fr != null)
                            ranges.put(fr.rangeId, (LivingEntity) e);
                    }
                }
            }
            if (ranges.size() == 0) return false;
            LivingEntity e;
            for(int range = 0; range <= maxRange / 1.3; range++) {
                e = ranges.get(range);
                if (e != null && isInFireRange(e)) {
                    target = e;
                    rotate(target);
                    targetLockTimer = currentTime;
                    return true;
                }
            }*/

private boolean findTarget() {
        boolean inRange = false;
        boolean inFireRange = false;
        LivingEntity tempTarget = null;
        if (target == null) {
            skullSmarts = Intelligence.DUMB; //TODO THIS NEEDS REMOVED !!! ONLY FOR DEBUG
            //if (!skullSmarts.equals(Intelligence.SMARTEST)) {
            for(ChunkCoords cc : chunkList) {
                for(Entity e : world.getChunkAt(cc.x, cc.z).getEntities()) {
                    if (e == null || e.isDead()) continue;
                    if (!(e instanceof LivingEntity) || (e instanceof Player && ((Player) e).getName().equals(skullCreator))) continue;
                    //if (e.hasMetadata("SkullWatch")) {
                    List<MetadataValue> meta = e.getMetadata("SkullWatch");
                    if (meta.size() > 0) {
                        long time = meta.get(0).asLong();
                        if (System.currentTimeMillis() - time > 5000)
                            e.removeMetadata("SkulLWatch", SkullWatch.plugin);
                        else
                            continue;
                    }
                    //}
                    LivingEntity le = (LivingEntity) e;
                    inRange = isInRange(le);
                    inFireRange = isInFireRange(le);
                    if (inRange && inFireRange) {
                        target = le;
                        rotate(target);
                        targetLockTimer = System.currentTimeMillis();
                        return true;
                    }
                    else if (inRange && !inFireRange) {
                        tempTarget = le;
                    }
                }
            }
            //}
            /*else { // TODO SMARTEST
             * 
             * Way Too Costly to do this.
             * 
                Map<Integer, LivingEntity> ranges = new HashMap<Integer, LivingEntity>();
                for(ChunkCoords cc : chunkList) {
                    for(Entity e : world.getChunkAt(cc.x, cc.z).getEntities()) {
                        if (e instanceof LivingEntity && isInRange((LivingEntity) e) && !(e instanceof Player && ((Player) e).getName().equals(skullCreator))) {
                            Location entLoc = e.getLocation();
                            RangeCoord rc = new RangeCoord(world, entLoc.getBlockX(), centerY, entLoc.getBlockZ());
                            FacingRange fr = directions.get(rc);
                            if (fr != null)
                                ranges.put(fr.rangeId, (LivingEntity) e);
                        }
                    }
                }
                if (ranges.size() == 0) return false;
                for(int range = 0; range <= maxRange / 1.3; range++) {
                    LivingEntity e = ranges.get(range);
                    if (e != null && isInFireRange(e)) {
                        target = e;
                        rotate(target);
                        targetLockTimer = System.currentTimeMillis();
                        return true;
                    }
                }
            }*/
        }
        else {
            if (target.isDead()) {
                target = null;
                return false;
            }
            inRange = isInRange(target);
            inFireRange = isInFireRange(target);
            if (inRange && inFireRange) {
                rotate(target);
                targetLockTimer = System.currentTimeMillis();
                return true;
            }
            else if (inRange && !inFireRange) {
                if (System.currentTimeMillis() - targetLockTimer > 2000) {
                    target = null;
                    targetLockTimer = System.currentTimeMillis();
                }
                rotate(target);
            }
        }
        if (tempTarget != null) {
            if (tempTarget.isDead()) return false;
            inRange = isInRange(tempTarget);
            inFireRange = isInFireRange(tempTarget);
            if (inRange && inFireRange) {
                target = tempTarget;
                rotate(target);
                targetLockTimer = System.currentTimeMillis();
                return true;
            }
        }
        return false;
    }
    
    private void getFiringSolution(LivingEntity potentialTarget) {
        Vector vect = null;
        Location skullLoc = getAxisAlignment();
        Location targetLoc = new Location(world, potentialTarget.getLocation().getX(), potentialTarget.getLocation().getY() + potentialTarget.getEyeHeight(), potentialTarget.getLocation().getZ());
        Vector toTarget = targetLoc.toVector().subtract(skullLoc.toVector());
        double speed = 1.5;
        double d0 = toTarget.getX();
        double d1 = toTarget.getY();
        double d2 = toTarget.getZ();
        float f2 = (float) Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);

        d0 /= f2;
        d1 /= f2;
        d2 /= f2;
        d0 *= speed;
        d1 *= speed;
        d2 *= speed;
        vect = new Vector(d0, d1, d2);
        if (skullSmarts.equals(Intelligence.DUMB)) {
            firingSolution = vect;
            return;
        }
        /* TODO 
         * 
         * Way too costly in processor to do this.
         * 
        Vector start = skullLoc.toVector();
        Vector direction = vect;
        try {
            BlockIterator lineOfSight = new BlockIterator(world, start, direction, 0, (int) fireRange);
            while (lineOfSight.hasNext()) {
                Block b = lineOfSight.next();
                if (b.getLocation().equals(getLocation())) continue;
                if (!b.getType().equals(Material.AIR)) {
                    firingSolution = null;
                    return;
                }
            }
            firingSolution = vect;
        } catch (Exception e) {
            firingSolution = null;
            return;
        }*/
    }
    
    private void debug() {
        /*
        for(Entry<RangeCoord, FacingRange> rcSet : directions.entrySet()) {
            RangeCoord rc = rcSet.getKey();
            FacingRange fr = rcSet.getValue();
            if (fr.rangeId == 1) {
                rc.getLocation().getBlock().setType(Material.STONE);
            }
            else if (fr.rangeId == 2) {
                rc.getLocation().getBlock().setType(Material.DIRT);
            }
            else if (fr.rangeId == 3) {
                rc.getLocation().getBlock().setType(Material.COBBLESTONE);
            }
            else if (fr.rangeId == 4) {
                rc.getLocation().getBlock().setType(Material.COAL_ORE);
            }
            else if (fr.rangeId == 5) {
                rc.getLocation().getBlock().setType(Material.IRON_ORE);
            }
            else if (fr.rangeId == 6) {
                rc.getLocation().getBlock().setType(Material.SANDSTONE);
            }
            else if (fr.rangeId == 7) {
                rc.getLocation().getBlock().setType(Material.WOOD);
            }
            else if (fr.rangeId == 8) {
                rc.getLocation().getBlock().setType(Material.LOG);
            }
            else if (fr.rangeId == 9) {
                rc.getLocation().getBlock().setType(Material.COAL_BLOCK);
            }
            else if (fr.rangeId == 10) {
                rc.getLocation().getBlock().setType(Material.IRON_BLOCK);
            }
            else if (fr.rangeId == 11) {
                rc.getLocation().getBlock().setType(Material.GOLD_BLOCK);
            }
            else {
                rc.getLocation().getBlock().setType(Material.CLAY);
            }
        }
        */
    }

    @SuppressWarnings("unused")
    private void debug1() {
        for(Entry<RangeCoord, FacingRange> rcSet : directions.entrySet()) {
            RangeCoord rc = rcSet.getKey();
            BlockFace face = rcSet.getValue().face;
            if (face.equals(BlockFace.NORTH_WEST)) {
                rc.getLocation().getBlock().setType(Material.STONE);
            }
            else if (face.equals(BlockFace.NORTH_NORTH_WEST)) {
                rc.getLocation().getBlock().setType(Material.DIRT);
            }
            else if (face.equals(BlockFace.NORTH)) {
                rc.getLocation().getBlock().setType(Material.COBBLESTONE);
            }
            else if (face.equals(BlockFace.NORTH_NORTH_EAST)) {
                rc.getLocation().getBlock().setType(Material.COAL_ORE);
            }
            else if (face.equals(BlockFace.NORTH_EAST)) {
                rc.getLocation().getBlock().setType(Material.IRON_ORE);
            }
            else if (face.equals(BlockFace.EAST_NORTH_EAST)) {
                rc.getLocation().getBlock().setType(Material.SANDSTONE);
            }
            else if (face.equals(BlockFace.EAST)) {
                rc.getLocation().getBlock().setType(Material.WOOD);
            }
            else if (face.equals(BlockFace.EAST_SOUTH_EAST)) {
                rc.getLocation().getBlock().setType(Material.LOG);
            }
            else if (face.equals(BlockFace.SOUTH_EAST)) {
                rc.getLocation().getBlock().setType(Material.COAL_BLOCK);
            }
            else if (face.equals(BlockFace.SOUTH_SOUTH_EAST)) {
                rc.getLocation().getBlock().setType(Material.IRON_BLOCK);
            }
            else if (face.equals(BlockFace.SOUTH)) {
                rc.getLocation().getBlock().setType(Material.GOLD_BLOCK);
            }
            else if (face.equals(BlockFace.SOUTH_SOUTH_WEST)) {
                rc.getLocation().getBlock().setType(Material.CLAY);
            }
            else if (face.equals(BlockFace.SOUTH_WEST)) {
                rc.getLocation().getBlock().setType(Material.DOUBLE_STEP);
            }
            else if (face.equals(BlockFace.WEST_SOUTH_WEST)) {
                rc.getLocation().getBlock().setType(Material.EMERALD_BLOCK);
            }
            else if (face.equals(BlockFace.WEST)) {
                rc.getLocation().getBlock().setType(Material.HAY_BLOCK);
            }
            else if (face.equals(BlockFace.WEST_NORTH_WEST)) {
                rc.getLocation().getBlock().setType(Material.WOOL);
            }
            else if (face.equals(BlockFace.DOWN)) {
                rc.getLocation().getBlock().setType(Material.REDSTONE_BLOCK);
            }
        }
    }
    
        public void clearDebug() {
        /*
        for(RangeCoord rc : directions.keySet()) {
            rc.getLocation().getBlock().setType(Material.AIR);
            rc.getLocation().getBlock().setData((byte) 0);
            rc.y = rc.y + 1;
            rc.getLocation().getBlock().setType(Material.AIR);
            rc.getLocation().getBlock().setData((byte) 0);
            skullBlock.setType(Material.AIR);
            skullBlock.setData((byte) 0);
        }
        */
    }
    
     public static UUID getUUIDFromPlayerName(String name) throws Exception {
        if (!SkullTurret.FORCEONLINEUUIDCHECK) {
            for(OfflinePlayer op : Bukkit.getOfflinePlayers()) {
                if (op.getName().equals(name)){
                    return op.getUniqueId();
                }
            }
            return new FindUUID(name).call();
        }
        else
            try {
                UUID id = new FindUUID(name).call();
                return id;
            } catch (Exception e) {
                for(OfflinePlayer op : Bukkit.getOfflinePlayers()) {
                    if (op.getName().equals(name)) return op.getUniqueId();
                }
                throw e;
            }
    }